package com.my.adminservice.config.controller;


import com.my.adminapi.config.domain.dto.*;
import com.my.adminapi.config.domain.vo.DictionaryDataVo;
import com.my.adminapi.config.domain.vo.DictionaryTypeVO;
import com.my.adminapi.config.feign.DictionaryFeignClient;
import com.my.adminservice.config.service.ISysDictionaryService;
import com.my.mycommondomain.domian.R;
import com.my.mycommondomain.domian.vo.BasePageVO;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class DictionaryController implements DictionaryFeignClient {
    @Autowired
    private ISysDictionaryService iSysDictionaryService;

    /**
     * 新增字典类型
     * @param dictionaryTypeWriteReqDTO 新增字典类型DTO
     * @return Long
     */
    @PostMapping("/dictionary_type/add")
    public R<Long> addType(@RequestBody @Validated DictionaryTypeWriteReqDTO dictionaryTypeWriteReqDTO) {
        return R.ok(iSysDictionaryService.addType(dictionaryTypeWriteReqDTO));
    }

    @GetMapping("/dictionary_type/list")
    public R<BasePageVO<DictionaryTypeVO>> listType(@Validated DictionaryTypeListReqDTO DictionaryTypeListReqDTO) {
        return R.ok(iSysDictionaryService.listType(DictionaryTypeListReqDTO));
    }

    /**
     * 编辑字典类型
     * @param dictionaryTypeWriteReqDTO 字典类型DTO
     * @return id
     */
    @PostMapping("/dictionary_type/edit")
    public R<Long> editType(@RequestBody @Validated DictionaryTypeWriteReqDTO dictionaryTypeWriteReqDTO) {
        return R.ok(iSysDictionaryService.editType(dictionaryTypeWriteReqDTO));
    }

    /**
     * 新增字典数据
     * @param dictionaryDataWriteDTO 入参
     * @return id
     */
    @PostMapping("/dictionary_data/add")
    public R<Long> addData(@RequestBody @Validated DictionaryDataWriteReqDTO dictionaryDataWriteDTO){
        return R.ok(iSysDictionaryService.addData(dictionaryDataWriteDTO));
    }

    /**
     * 查询字典数据列表
     * @param DictionaryDataListReqDTO 入参
     * @return 字典数据列表
     */
    @GetMapping("/dictionary_data/list")
    public R<BasePageVO<DictionaryDataVo>> dataList(@Validated DictionaryDataListReqDTO DictionaryDataListReqDTO) {
        BasePageVO<DictionaryDataVo> result= iSysDictionaryService.dataList(DictionaryDataListReqDTO);
        return R.ok(result);
    }

    @PostMapping("/dictionary_data/edit")
    public R<Long> editData(@RequestBody @Validated DictionaryDataEditReqDTO dto){
        Long result=iSysDictionaryService.editData(dto);
        return R.ok(result);
    }


    @Override
    public List<DictionaryDataDTO> selectDictDataByType(String typeKey) {
        List<DictionaryDataDTO> list=iSysDictionaryService.selectDictDataByType(typeKey);
        return list;
    }

    @Override
    public Map<String, List<DictionaryDataDTO>> selectDictDataByTypes(List<String> typeKeys) {
        Map<String,List<DictionaryDataDTO>> result=iSysDictionaryService.selectDictDataByTypes(typeKeys);
        return result;
    }

    @Override
    public DictionaryDataDTO getDicDataByKey(String dataKey) {
        DictionaryDataDTO result=iSysDictionaryService.getDicDataByKey(dataKey);
        return result;
    }

    @Override
    public List<DictionaryDataDTO> getDicDataByKeys(List<String> dataKeys) {
        List<DictionaryDataDTO> result=iSysDictionaryService.getDicDataByKeys(dataKeys);
        return result;
    }
}
